package cn.wolfcode.web.controller;

import cn.wolfcode.common.web.Result;
import cn.wolfcode.domain.SeckillProduct;
import cn.wolfcode.domain.SeckillProductVo;
import cn.wolfcode.service.ISeckillProductService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Created by lanxw
 * 秒杀商品信息查询
 */
@RestController
@RequestMapping("/seckillProduct")
@Slf4j
public class SeckillProductController {
    @Autowired
    private ISeckillProductService seckillProductService;

    /**
     * 提供elasticJob定时调度查询当天的秒杀商品列表
     *
     * @param time
     * @return
     */
    @GetMapping("/queryByTimeForJob")
    public Result<List<SeckillProductVo>> queryByTimeForJob(Integer time) {
        List<SeckillProductVo> seckillProductVos = seckillProductService.queryByTime(time);
        return Result.success(seckillProductVos);
    }

    /**
     * 从缓存中查询当天的秒杀商品列表
     *
     * @param time
     * @return
     */
    @GetMapping("/queryByTime")
    public Result<List<SeckillProductVo>> queryByTime(Integer time) {
        List<SeckillProductVo> seckillProductVos = seckillProductService.queryByTimeFromCache(time);
        return Result.success(seckillProductVos);
    }

    @GetMapping("/find")
    public Result<SeckillProductVo> find(Integer time,Long seckillId) {
        SeckillProductVo vo = seckillProductService.findFromCache(time,seckillId);
        return Result.success(vo);
    }

}
